<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
	
		</style>
		<link rel="stylesheet" type="text/css" href="js/bootstarp-3.3.7/css/bootstrap.min.css"/>
		<script src="js/jquery/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
		<script src="js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>
	
		<script src="assets/layui-v2.4.5/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="assets/layui-v2.4.5/layui/css/layui.css" />


	</head>
	
	<script>
			$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
				$.ajaxSetup({
					crossDomain: true,
					xhrFields: {
						withCredentials: true
					}
				});
			});
		</script>
	<body>

		<div class="container">
	


<!-- Modal  11111111111111111111111我是作废-->
<!--
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title"   id="myModalLabel"><font color="darkred" size="3"><span class="glyphicon glyphicon-exclamation-sign"> 警告</span></font></h4>
      </div>
  <!--    <div class="modal-body">
       &nbsp;&nbsp;&nbsp;&nbsp; <strong > <font color="darkred" size="5">作废之后不可恢复!!!</font></strong>
        <span id="number" ></span>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-default"  onclick="zuofei()" > <strong> <font color="darkred" size="3">确定 </font></strong> </button>
      </div> -->
    </div>
  </div>
</div>
		
		
		<!-- Modal1  end-->
		
		<!-- Modal 222222222222222          退款模态框-->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">挂号【退款】</h4>
      </div>
      <div class="modal-body">
    
         <ul id="myTab" class="nav nav-tabs">
    <li class="active">
        <a href="#home" data-toggle="tab">
             退款
        </a>
    </li>
    <li><a href="#ios" data-toggle="tab">支付记录 </a></li>

</ul>
<div id="myTabContent" class="tab-content">
    <div class="tab-pane fade in active" id="home">
    	
   	<table  bgcolor="#000000" width="400" height="150" >
   		    <tr>
        		<td width="50%">患者姓名：</td>
        		<td align="right" id="hzxm" style="position: relative;right: -125px;"></td>
        	</tr>
    	    <tr>
        		<td width="50%">科室名称</td>
        		<td align="right" id="ksmc" style="position: relative;right: -125px;"></td>
        	</tr>
           <tr>
        		<td >挂号时间</td>
        		<td align="right"  id="ghsj" style="position: relative;right: -125px;">  </td>
        	</tr>
            <tr>
        		<td >挂号费用</td>
        		<td align="right" id="fy" style="position: relative;right: -100px;">  </td>
        		<td align="right" style="position: relative;left: 98px;">(元)</td>
        	</tr>
        	</table>
        	<hr style="filter: progid:dximagetransform.microsoft.glow(color="#987cb9",strength=10)" width="100%" color="#987cb9" size=1>

         <table id="TKtablel"  width="100" height="100" >
         	<tr>
         		<td>
         			<table width="500" height="100" >
         				<input type="hidden" id="cyid" />
         				<input type="hidden" id="patient_id" />
         				<input type="hidden" id="registration_id" />
         				<input type="hidden" id="order_id" />
         				<tr>
         					<td><font size="3">退款金额:</font></td>
         					<td align="right" >￥<font color="red" size="5" id="fyje">0.00</font></td>
         				</tr>        			

         				<tr>
         					<td>&nbsp;</td>
         				</tr>
         				<tr>
         					<td colspan="2"><textarea  style="width:500px;height:60px;">退款说明</textarea></td>
         					
         				</tr> 
         			</table>
         		</td>
         	</tr>
         </table>
         
               <div class="modal-footer">
                   <button   class="btn btn-danger btn-lg btn-block"  id="affirm_refund">退款</button>
               </div>   
    </div>
    
    <div class="tab-pane fade" id="ios">
    	  	<table  bgcolor="#000000" width="200" height="400" >
     	  				 	<tr>
    	  				 		<td >现金</td>
        		                <td align="right" id="xj">  </td>
    	  				 	</tr>
    	  </table>	
   </div>
</div>
     </div>
      </div>-->
    </div>
  </div>
</div>
		 
		<!-- Modal 2222222222222222222222222  end-->
		
			
		<!-- Modal 333333333333    收费模态框-->
		<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">收费</h4>
					</div>
					<div class="modal-body">


					<form class="form-horizontal" id="for3">
					 <div class="form-group">
					 	<input type="hidden" id="registration_id"  name="registration_id"/>
					 	<table>
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>门诊编号:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="mzbh"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>时间/日期:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="rqsj"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>科室名称:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="ksxm"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>医生姓名:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="ysxm"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>挂号类型:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="ghlx"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>挂号费:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="ghfy"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		<tr>
					 			<td width="16%"></td>
					 			<td><p>应收:</p></td>
					 			<td width="20%"></td>
					 			<td width="20%"><span id="ghfys"></span></td>
					 			<td width="16%"></td>
					 		</tr>
					 		<tr>
					 			
					 		</tr>
					 	</table>
    					
    							
  				</div> 
						</form>		
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-success glyphicon glyphicon-usd"  id="gopay" ></button>
					</div>
				</div>
			</div>
		</div>
		
		
		<!-- Modal3  end-->
		<table align="center">
			<tr>
			<td>
				<!--
                	作者：offline
                	时间：2018-11-15
                	描述：
                	
                -->
				<!--<form class="form-horizontal" role="form">-->
				<!--<div  width="1000" height="30">
					<tr>
						
						<input  type="text" name="name" id="na" />
						
						        状态: <select name="registration_status" id="registration_status" >
							<option value="0">全部</option>
							<option value="1">待就诊</option>
							<option value="2">已就诊</option>
							<option value="3">已退号</option>
							<option value="4">作废</option>
							<option value="5">未付款</option>
						         </select>
							挂号日期:<input type="date" name="startdate" id="startdate"/> - <input type="date" name="enddate" id="enddate" />	&nbsp;&nbsp;&nbsp;&nbsp;	
							<button class="btn btn-primary " id="cx"><span class="glyphicon glyphicon-search"></span>查询</button>	
						
					</tr>
				</div>-->
				
				
				
				
			<div align="center">
			<form class="form-inline">
				<div class="form-group">
					<br />
					<label for="exampleInputEmail2">患者姓名：</label>
					<input type="text" class="form-control" id="patient_name" name="name" placeholder="请输入患者姓名">	
					<label for="exampleInputEmail2">状态：</label>	
						<select class="form-control" id="registration_status" name="registration_status">
						    <option value="">请选择状态</option>
						    <option value="1">待就诊</option>
							<option value="2">已就诊</option>
							<option value="3">已退号</option>
							<option value="4">已作废</option>
							<option value="5">未付款</option>
							<option value="6">部分支付</option>
					</select>
					<label for="exampleInputEmail2">挂号日期:</label>
					<input class="form-control" type="date" name="startdate" id="startdate"/> 
					- <input class="form-control" type="date" name="enddate" id="enddate" />	&nbsp;&nbsp;&nbsp;&nbsp;
					<button type="button" class="btn btn-primary glyphicon glyphicon-search"id="cx" >查询</button>
				</div>
			</form>
		</div>
				
				
				
					<!--</form>-->
					<!-- -->
			</td>	
			</tr>
			<tr>
			<td>
				<table align="center" width="1000" height="" bgcolor="gray">
					<tr align="center" >
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<td>
							 
 						<table id="tab" align="center" bgcolor="#DDDDDD"></table>
 							
						</td>
					</tr>
				</table>
			</td>	
			</tr>
		</table>
	
		
	</div>
	</body>
 </html>
<script>
	   	      
	
	// 点击单选按钮后触发，即，我们选择"现金退回"时，触发一个事件，弹出选中的值
     
	     $("#ylth").click(function(){
	     	 $("#xxjj").hide();
	     })
	    $("#xjth").click(function(){
	     	 $("#xxjj").show();	
	     })
	
	$(function(){
		
		

layui.use(['form', 'layedit', 'laydate','element'], function() {
					var form = layui.form,
						layer = layui.layer,
						layedit = layui.layedit,
						laydate = layui.laydate;

				});

		
		
		
		
		
	   $('#tab').bootstrapTable({
       url: 'http://localhost:8091/dzm_his_Registration',
       type:"post",
       pagination: true,//分页
	   pageSize: 5,//页面显示的数据
	   queryParams : queryParams,//综合查询的代码
    columns: [{
        field: 'registration_number',
        title: '挂号编号',
        align: 'center',
		valign: 'middle',
    }, {
        field: 'registration_amount',
        title: '挂号费(元)',
        align: 'center',
		valign: 'middle',        
    }, {
        field: 'department_name',
        title: '科室名称',
        align: 'center',
		valign: 'middle',
    },{
        field: 'true_name',
        title: '医生姓名',
        align: 'center',
		valign: 'middle',       
    },{
        field: 'name',
        title: '患者姓名',
        align: 'center',
		valign: 'middle',        
    },{
        field: 'create_time',
        title: '挂号时间',
        align: 'center',
		valign: 'middle',        
    }, {
        field: 'true_name',
        title: '操作员',
        align: 'center',
		valign: 'middle',        
    }, {
        field: 'type_id',
        title: '挂号类型',
        align: 'center',
		valign: 'middle',
		formatter:function(value,data){
		if(value=="0"){
			return "初诊" ;
		}if(value=="1"){
			return "急诊" ;
		}if(value=="2"){
			return "复诊" ;
		}
		} 
    }, {
        field: 'registration_status',
        title: '挂号状态',
        align: 'center',
		valign: 'middle', 
		formatter:function(value,data){
		if(value=="1"){
			return "待就诊" ;
		}if(value=="2"){
			return "已就诊" ;
		}if(value=="3"){
			return "已退款" ;
		}if(value=="4"){
			return "已作废" ;
		}if(value=="5"){
			return "未付款" ;
		}if(value=='6'){
			return "部分支付";
		}
		} 
    }, {
        field: 'caozuo',
        title: '操作',
        align: 'center',
		valign: 'middle', 
		formatter:function(value,row,index){
         if(row.registration_status==1){
			    var zuofei=	"<button class='btn btn-danger glyphicon' data-toggle='modal' data-target='#myModal1' onclick='zuofeiRegistration("+row.registration_id+")'>作废</button>"
			    var tuikuan = "<button class='btn btn-primary ' data-toggle='modal' data-target='#myModal2' onclick='tuikuan("+row.registration_id+")' >退款</button>";
	         	return "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+tuikuan+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+zuofei;
			}else if(row.registration_status==2){
	         	return "<button class='btn' type='button' disabled='disabled'>已就诊</button>";
			}else if(row.registration_status==4){				
				return "<button class='btn' type='button' disabled='disabled'><span class='glyphicon glyphicon-exclamation-sign'></span>已作废</button>";
			}else if(row.registration_status==3){	
				return "<button class='btn' type='button' disabled='disabled'>已退款</button>";
			}else {
				return '<button class="btn btn-danger glyphicon" data-toggle="modal" data-target="#myModal3" onclick="findRegistration('+row.registration_id+')" >去付款</button>';
			}
		}
    }]
});
function queryParams(params){
	var temp = {
		'name' : $("#patient_name").val(),
		'registration_status' : $("#registration_status").val(),
	    'startdate'  : $("#startdate").val(),
		'enddate' : $("#enddate").val(), 
	}
	return temp;
}
  
              $("#cx").click(function() {
					$("#tab").bootstrapTable("refresh");
					$("#na").val("");
					$("#registration_status").val(0);
					$("#startdate").val("");
					$("#enddate").val("");
					//alert($("#na").val()+$("#registration_status").val()+$("#startdate").val()+$("#enddate").val())
				
				});		
			
				 /*确认退款-----》》》》》》》》       ---状态变已退款    value=3*/
				 $("#affirm_refund").click(function(){
				 	console.log($("#cyid").val());
				 	console.log($("#fyje").html());
				 	
				 	layer.confirm("确认退款？",function(index){
				 		$.ajax({
					       type: "post",
					       url: "http://localhost:8091/updateTow",
					    data:"patient_id=" + $("#cyid").val()+"&money="+$("#fyje").html(), 
						success: function(data) {
							   if(data.msg=='true'){
							   	alert("退款成功！");
								$("#myModal2").modal("hide");
				   			    $("#tab").bootstrapTable("refresh");
							}else{
								alert("退款失败")
							}
					        }
				        });  
				 	})
				}) 
				
				
				$("#gopay").click(function(){
					var registration_id = $("#registration_id").val();
					var patient_id = $("#patient_id").val()
					var order_id = $("#order_id").val()
					var money = $("#gopay").html();
					var casecode = getCaseCode();
					console.log(registration_id);
					console.log(patient_id);
					console.log(order_id);
					console.log(money);
					console.log(casecode);
					if(confirm("金额是否到账？")==false){
						$("#myModal3").modal("hide");
					}else{
						$.ajax({
						    type: "post",
							url: "http://localhost:8091/pays/gopay",
							data:"registration_id="+registration_id+"&patient_id="+patient_id+"&order_id="+order_id+"&money="+money+"&case_code="+casecode,
							success: function(data) {
							   if(data.msg=='true'){
							   	  $("#myModal3").modal("hide");
							   	  alert("支付成功！");
							   	  $("#tab").bootstrapTable("refresh");
							   	  $("#registration_id").val("");
							   }else{
							   	  $("#myModal3").modal("hide");
							   	  alert("支付失败！");
							   	  $("#registration_id").val("");
							   }
							
							}
					});
					}
					
				})
})				
				
		          /*点击退款（tuikuan）渲染页面 ----》》》》》查询*/
	            function tuikuan(registration_id) {
			 	        $.ajax({
					       type: "POST",
					       url: "http://localhost:8091/findRegistration",
					       data:"registration_id=" + registration_id,
						   success: function(data) {
							$("#cyid").val(data[0].patient_id);
							$("#hzxm").html(data[0].name);
							$("#ksmc").html(data[0].department_name)
							$("#ghsj").html(data[0].create_time)
							$("#fy").html(data[0].registration_amount)
							$("#fyje").html(data[0].registration_amount)
					           }
				        }); 
			      }	  
	            
	        function getCaseCode() {
				var code = new Date();
				var year = code.getFullYear();
				var mon = code.getMonth();
				var day = code.getDay();
				var hour = code.getHours();
				var min = code.getMinutes();
				var secon = code.getSeconds();
				var ms = code.getMilliseconds();
				var caseCode = year + "" + mon + "" + day + "" + hour + "" + min + "" + secon + "" + ms
				return caseCode;
			}
	
	                /* findRegistration  付费    ----》》》》》查询*/
	         
	              function findRegistration(registration_id) {
	              	
			 	        $.ajax({
					       type: "post",
					       url: "http://localhost:8091/ghlb/Registration",
					       data: "registration_id=" + registration_id,
						success: function(data) {
						$("#registration_id").val(data[0].registration_id);
						$("#patient_id").val(data[0].patient_id);
						$("#order_id").val(data[0].id);
						$("#mzbh").html(data[0].registration_number);
						$("#rqsj").text(data[0].create_time);
						$("#ksxm").text(data[0].department_name);
						$("#ysxm").text(data[0].true_name);
						$("#ghlx").text(data[0].type_id);
						$("#ghfy").text(data[0].registration_amount);
						$("#ghfys").text(data[0].registration_amount);
						$("#gopay").html(data[0].registration_amount)
					           }
				        });  
			      }	  
			      
			      
			      /*zuofeiRegistration 确认作废事件  */
			            function zuofeiRegistration(registration_id) {
			            	if(confirm("确定作废？")==false){
			           		$("#tab").bootstrapTable("refresh");
			            	}else {
			            	$.ajax({
					        type: "post",
					        url: "http://localhost:8091/updateRegistration",
					        data:{"registration_id":registration_id},
						    success: function(data) {
						    	if(data.msg=='true'){
						    		alert("作废成功！");
						    		$("#tab").bootstrapTable("refresh");
						    	}
					       }
				        });  
			           }
			            
			     
			       }	
			       
			       
			       
			       
			       
			       
			       
			       
			   
</script>

  